package com.jy.adscm.operation.aftersales.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;

import com.jy.adscm.operation.aftersales.bean.QueryShylMaterial;
import com.jy.adscm.operation.aftersales.bean.ShylMaterial;
import com.jy.adscm.operation.aftersales.service.ShylMaterialService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.system.mapper.mysql.JyCodeMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 售后原料任务 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-08-12
 */
@RestController
@RequestMapping("/adscm/operation/aftersales/shylMaterial")
public class ShylMaterialController {

    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    ShylMaterialService shylMaterialService;
    @Autowired
    JyCodeMapper jyCodeMapper;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody ShylMaterial shylMaterial, HttpServletRequest request) throws AdscmSystemException {
//        String tokenId = request.getParameter("tokenId");
//        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
//        shylMaterial.setTaskreleaseperson(token.getUser().getId().toString());
//        shylMaterial.setTaskreleaseaddtime(new Date());
//        shylMaterial.setTaskfinishstate(0);
//        shylMaterial.setTaskstate(0);
//        shylMaterial.setIstaskstart(0);
//        shylMaterial.setIstaskbegin(0);
//        shylMaterial.setIstaskend(0);
//        shylMaterial.setIsreviewtask(0);
//        shylMaterial.setReviewresult(-1);
//
//        boolean insert = shylMaterialService.insertShylMaterial(shylMaterial);
        return new SimpleCoreResponse("200","新增成功",null);
    }

    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id)throws AdscmSystemException {
        boolean result = shylMaterialService.deleteById(id);
        return new  SimpleCoreResponse("200","删除成功",result);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody ShylMaterial shylMaterial, HttpServletRequest request) throws AdscmSystemException{
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result = shylMaterialService.updateShylMaterialy(shylMaterial,token);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("selectshylMaterial")
    public  SimpleCoreResponse  selectshylMaterial(@RequestBody QueryShylMaterial queryShylMaterial) throws  AdscmSystemException{
        Page<ShylMaterial> page =new Page<>(queryShylMaterial.getCurrentPage(),queryShylMaterial.getPageSize());
        page= shylMaterialService.selectShylMaterial(page,queryShylMaterial);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("selectInStock")
    public  SimpleCoreResponse  selectInStock() throws  AdscmSystemException{

     List<ShylMaterial> shylMaterials= shylMaterialService.selectInStock();
        return  new SimpleCoreResponse("200","查询成功",shylMaterials);
    }

}

